package com.zlict.admin.controller;

import com.zlict.admin.domain.ProjectAchievement;
import com.zlict.admin.service.IProjectAchievementService;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.core.page.TableDataInfo;
import com.zlict.common.enums.BusinessType;
import com.zlict.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目成果Controller
 * 
 * @author dzw
 * @date 2025-06-11
 */
@RestController
@RequestMapping("/admin/achievement")
public class ProjectAchievementController extends BaseController
{
    @Autowired
    private IProjectAchievementService projectAchievementService;

    /**
     * 查询项目成果列表
     */
    @PreAuthorize("@ss.hasPermi('admin:achievement:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectAchievement projectAchievement)
    {
        startPage();
        List<ProjectAchievement> list = projectAchievementService.selectProjectAchievementList(projectAchievement);
        return getDataTable(list);
    }

    /**
     * 导出项目成果列表
     */
    @PreAuthorize("@ss.hasPermi('admin:achievement:export')")
    @Log(title = "项目成果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectAchievement projectAchievement)
    {
        List<ProjectAchievement> list = projectAchievementService.selectProjectAchievementList(projectAchievement);
        ExcelUtil<ProjectAchievement> util = new ExcelUtil<ProjectAchievement>(ProjectAchievement.class);
        util.exportExcel(response, list, "项目成果数据");
    }

    /**
     * 获取项目成果详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:achievement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectAchievementService.selectProjectAchievementById(id));
    }

    /**
     * 新增项目成果
     */
    @PreAuthorize("@ss.hasPermi('admin:achievement:add')")
    @Log(title = "项目成果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectAchievement projectAchievement)
    {
        return toAjax(projectAchievementService.insertProjectAchievement(projectAchievement));
    }

    /**
     * 修改项目成果
     */
    @PreAuthorize("@ss.hasPermi('admin:achievement:edit')")
    @Log(title = "项目成果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectAchievement projectAchievement)
    {
        return toAjax(projectAchievementService.updateProjectAchievement(projectAchievement));
    }

    /**
     * 删除项目成果
     */
    @PreAuthorize("@ss.hasPermi('admin:achievement:remove')")
    @Log(title = "项目成果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectAchievementService.deleteProjectAchievementByIds(ids));
    }
}
